package com.hzcx.app.simplechat.model;

import android.content.Context;

import com.hzcx.app.simplechat.api.APIRequest;
import com.hzcx.app.simplechat.api.BaseObserver;
import com.hzcx.app.simplechat.api.BaseResponse;
import com.hzcx.app.simplechat.api.RxHelper;
import com.hzcx.app.simplechat.base.BaseEmptyBean;
import com.hzcx.app.simplechat.ui.moment.bean.MomentBean;
import com.hzcx.app.simplechat.ui.moment.bean.MomentCommentBean;
import com.hzcx.app.simplechat.ui.moment.bean.MomentInfoBean;
import com.hzcx.app.simplechat.ui.moment.bean.NewMessageCountBean;
import com.hzcx.app.simplechat.ui.moment.bean.NewMessageListBean;
import com.hzcx.app.simplechat.util.token.TokenUtils;

import java.util.List;

/**
 * 动态相关
 */
public class MomentModel {

    /**
     * 发布动态
     *
     * @param context
     * @param maincontent
     * @param dy_images
     * @param visible
     * @param linkurl
     * @param subscript
     * @param observer
     */
    public static void createMoment(Context context, String maincontent, String dy_images, int visible, String linkurl, int subscript,
                                    String lng,String lat,String address,
                                    BaseObserver<BaseEmptyBean> observer) {
        APIRequest
                .getRequestInterface()
                .createMoment(TokenUtils.getTokenHeader(), maincontent, dy_images, visible, linkurl, subscript,lng,lat,address)
                .compose(RxHelper.observableIO2Main(context))
                .subscribe(observer);
    }

    /**
     * 获取动态列表
     *
     * @param context
     * @param page
     * @param observer
     */
    public static void getMomentList(Context context, int page, String id, BaseObserver<List<MomentBean>> observer) {
        APIRequest
                .getRequestInterface()
                .getMomentList(TokenUtils.getTokenHeader(), page, id)
                .compose(RxHelper.observableIO2Main(context))
                .subscribe(observer);
    }

    /**
     * 动态点赞
     *
     * @param context
     * @param id
     * @param observer
     */
    public static void momentFabulous(Context context, int id, BaseObserver<BaseEmptyBean> observer) {
        APIRequest
                .getRequestInterface()
                .momentFabulous(TokenUtils.getTokenHeader(), id)
                .compose(RxHelper.observableIO2Main(context))
                .subscribe(observer);
    }

    /**
     * 获取动态详情
     *
     * @param context
     * @param id
     * @param observer
     */
    public static void getMomentInfo(Context context, int id, BaseObserver<MomentInfoBean> observer) {
        APIRequest
                .getRequestInterface()
                .getMomentInfo(TokenUtils.getTokenHeader(), id)
                .compose(RxHelper.observableIO2Main(context))
                .subscribe(observer);
    }


    /**
     * 评论动态或评论
     *
     * @param context
     * @param dynamic_id
     * @param review_content
     * @param by_review_id
     * @param observer
     */
    public static void momentComment(Context context, int dynamic_id, String review_content, String by_review_id, BaseObserver<MomentCommentBean> observer) {
        APIRequest
                .getRequestInterface()
                .momentComment(TokenUtils.getTokenHeader(), dynamic_id, review_content, by_review_id)
                .compose(RxHelper.observableIO2Main(context))
                .subscribe(observer);
    }

    /**
     * 获取动态评论
     *
     * @param context
     * @param id
     * @param page
     * @param observer
     */
    public static void getMomentCommentList(Context context, int id, int page, BaseObserver<List<MomentCommentBean>> observer) {
        APIRequest
                .getRequestInterface()
                .getMomentCommentList(TokenUtils.getTokenHeader(), id, page)
                .compose(RxHelper.observableIO2Main(context))
                .subscribe(observer);
    }

    /**
     * 删除动态
     *
     * @param context
     * @param dynamic_id
     * @param observer
     */
    public static void deleteMoment(Context context, int dynamic_id, BaseObserver<BaseEmptyBean> observer) {
        APIRequest
                .getRequestInterface()
                .deleteMoment(TokenUtils.getTokenHeader(), dynamic_id)
                .compose(RxHelper.observableIO2Main(context))
                .subscribe(observer);
    }

    /**
     * 删除评论
     *
     * @param context
     * @param review_id
     * @param observer
     */
    public static void deleteComment(Context context, int review_id, BaseObserver<BaseEmptyBean> observer) {
        APIRequest
                .getRequestInterface()
                .deleteComment(TokenUtils.getTokenHeader(), review_id)
                .compose(RxHelper.observableIO2Main(context))
                .subscribe(observer);
    }

    /**
     * 获取新消息条数
     *
     * @param context
     * @param observer
     */
    public static void getNewMessageCount(Context context, BaseObserver<NewMessageCountBean> observer) {
        APIRequest
                .getRequestInterface()
                .getNewMessageCount(TokenUtils.getTokenHeader())
                .compose(RxHelper.observableIO2Main(context))
                .subscribe(observer);
    }

    /**
     * 获取新消息列表
     *
     * @param context
     * @param page
     * @param observer
     */
    public static void getNewMessageList(Context context, int page, BaseObserver<List<NewMessageListBean>> observer) {
        APIRequest
                .getRequestInterface()
                .getNewMessageList(TokenUtils.getTokenHeader(), page)
                .compose(RxHelper.observableIO2Main(context))
                .subscribe(observer);
    }

    /**
     * 清空消息列表
     *
     * @param context
     * @param observer
     */
    public static void clearNewMessageList(Context context, BaseObserver<BaseEmptyBean> observer) {
        APIRequest
                .getRequestInterface()
                .clearNewMessageList(TokenUtils.getTokenHeader())
                .compose(RxHelper.observableIO2Main(context))
                .subscribe(observer);
    }

    /**
     *  屏蔽此动态
     * @param context
     * @param dynamic_id
     * @param observer
     */
    public static void shieldMoment(Context context, int dynamic_id, BaseObserver<BaseEmptyBean> observer) {
        APIRequest
                .getRequestInterface()
                .shieldMoment(TokenUtils.getTokenHeader(), dynamic_id)
                .compose(RxHelper.observableIO2Main(context))
                .subscribe(observer);
    }
}
